import confige from "./confige.js";
import User from "./user.js"

export const myRequest = (options) =>{
	return new Promise((resolve,reject)=>{
		uni.request({
			url:confige.webUrl+options.url,
			method:options.method || "GET",
			data:options.data || {},
			header:options.header || {'Content-Type':'application/x-www-form-urlencoded','token':User.token},
			success: (res) => {
				// console.log(res)
				if(res.data.code == 401){
					uni.showToast({
						title:"登录已失效，请重新登录",
						icon:"none"
					});
					this.token = false;
					uni.removeStorageSync('token');
					reject(res);
				}
				resolve(res)
			},
			fail: (err) => {
				console.log(err)
				uni.showToast({
					title:"请求失败",
					icon:"none"
					
				})
				reject(err);
			}
		})
	}
	)
}
